//
//  UIFont+fontSize.m
//  

#import "UIFont+fontSize.h"
#import <objc/runtime.h>

#define kScale MIN([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) / 375

#define kDefaultWidth  390

@implementation UIFont (fontSize)

+ (void)load{

static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];
        
        Method orignalMethod = class_getClassMethod(class, @selector(systemFontOfSize:));
        
        Method myMethod = class_getClassMethod(class, @selector(test_systemFontOfSize:));
        
        method_exchangeImplementations(orignalMethod, myMethod);
        
        Method orignalMethod2 = class_getClassMethod(class, @selector(boldSystemFontOfSize:));
        
        Method myMethod2 = class_getClassMethod(class, @selector(test_boldSystemFontOfSize:));
        
        method_exchangeImplementations(orignalMethod2, myMethod2);
    
    });
}

+ (UIFont *)test_systemFontOfSize:(CGFloat)fontSize{
    if (kScreenWidth <= kDefaultWidth) {
        UIFont *font = [UIFont test_systemFontOfSize:fontSize];
        return font;
    }
    UIFont *font = [UIFont test_systemFontOfSize:fontSize*kScreenWidth/kDefaultWidth];
    return font;
}

+ (UIFont *)test_boldSystemFontOfSize:(CGFloat)fontSize{
    if (kScreenWidth <= kDefaultWidth) {
        UIFont *font = [UIFont test_boldSystemFontOfSize:fontSize];
        return font;
    }
    UIFont *font = [UIFont test_boldSystemFontOfSize:fontSize*kScreenWidth/kDefaultWidth];
    return font;
}


@end
